
<!--
 * @Author: tansq
 * @Date: 2022-09-02 15:42:41
 * @LastEditTime: 2022-11-15 15:47:34
 * @LastEditors: tansq
 * @Description: 科技普通审批页面
 * @FilePath: \hte-vue-dev\src\views\tech\ApprovalInfo.vue
 * 可以输入预定的版权声明、个性签名、空行等
-->

<template>
  <div class="process-engine content" style="width:100%; " >
            <htApproval
              v-if="processInstanceId"
              ref="approvalRef"
              :process-instance-id="processInstanceId"
              :options="options"
              :custom="custom"
              @submit="afterSubmit"
              :before-submit="beforeSubmit"
              @cancelSubmit="afterSubmit"
              @reject="afterReject"
              @back="backAction"
              :task-load="taskLoad"
              :before-reject="beforeReject"
              :before-back="beforeReject"
              :show-task-history="true"
              :showPrintBtn="false"
              :show-upload-btn="showApprovalUpload"
              :attach-preview="handleApprvalPreview"
              :snapshotConfigs="snapshotConfigs"
               :hidden-task-def-key="hiddenTaskDefKey"
            >
            </htApproval>
            <a-empty v-if="!processInstanceId" description="暂无数据" />

            </div>
</template>

<script>
import {getAction, postAction, previewAttach} from '@/api/manage';
import Vue from 'vue';
import '@/utils/upload.install.js';
import '@/config/hteupload.install.js';
import '@/config/ht-approval.install.js';
import {ACCESS_TOKEN, USER_NAME} from '@/store/mutation-types'
import {codeInfoList,codeInfoByTypeAndParent} from '@/api/codeInfo'
import {Modal} from 'ant-design-vue'
import {formatSize, isPreview} from '@/components/hteUpload/common/utils'
import {downloadAttach} from '@/components/hteUpload/api/upload'
import {Base64} from 'js-base64'
import {filterHasPermission} from '@/utils/hasPermission'
import moment from 'moment';
import debounce from 'lodash/debounce'
// import {handleApprvalPreview} from '@/utils';
export default {
  name: 'ApprovalInfo',
  components: {
    ProcessUserSelect: () => import('@/components/tools/projectBuildStup/ProcessUserSelect'),
    htApproval: () => import('@/config/ht-approval.umd.min.js'),
  },
  inject:['parentThis'],
  props:{
    processInstanceId: {
       // 流程实例ID
      type:String,
      require:false,
      default:'',
    }
  } ,  
  data() {
    this.beforeSubmit =debounce(this.beforeSubmit,500)
    return {
    showApprovalUpload: false,
     
    options: {
        request: {
          baseUrl: this.API_BASE_URL, // 业务系统根路径
          timeOut: 60000 * 5, // 请求超时时间
          interceptors: (config) => {
            config.headers['X-Access-Token'] = Vue.ls.get(ACCESS_TOKEN)
            return config
          },
        },
        userId: Vue.ls.get(USER_NAME),
      },
      messageId: '', // 工作台URL里面的msgId参数
      hiddenTaskDefKey: 'submit',
      custom: {},
      historyDialog: {
        // 审批历史模态框属性
      },
      taskType: 0, // 任务类型，默认0：待办任务，1：抄送任务，2：已办 任务
      // 自定义变量，可覆盖发起流程时传入的变量
      custom: {
        lawUser: null
      },
      // 表单快照配置
      snapshotConfigs: [
        {
          type: 'ref',
          value: 'imageWrapper'
        }
      ],
     
      wrapperCol: { span: 18 },
      url: {
       
      },
      currentKey:''
    };
  },
  mounted() {
  },
  methods: {
    handleApprvalPreview(attach){
      
      attach.dbKey = 'Sac'
      if(isPreview(attach.fileName)){
        previewAttach(attach).then(result=>{
          const url=URL.createObjectURL(result)
          window.open(process.env.BASE_URL+'/pdf/web/viewer.html?file=' + url)
        }).catch(err => {
          this.$message.warning('下载文件失败');
        })
      }else{
        let href =
          this.API_BASE_URL +'/tp/attach/download?id=' +
          attach.id +
          '&dbKey=Sac&ftpKey='+attach.ftpKey+'&token=' +
          Vue.ls.get(ACCESS_TOKEN)+'&fullfilename='+attach.fileName
        window.open(process.env.VUE_APP_ONLINE_BASE_URL+'?url='+encodeURIComponent(Base64.encode(href)));
      }
    },
    taskLoad(task){
      console.log('当前节点' , task)

    },
    beforeSubmit(){
      this.$refs.approvalRef.submitTaskNotBefore();
    },
   
    beforeReject(res) {
       console.log("退回前:"+JSON.stringify(res))
       
      if (!this.$refs.approvalRef.data) {
        this.$message.error('请填写意见');
        return false;
      }
      return true;
    },
    afterSubmit(res) {
      // 用户点击提交后成功返回后的处理
      const that = this;

      that.parentThis.initData()
    },

    backAction(res) {
      // 退回
      console.log("退回:"+JSON.stringify(res))
      
      const that = this;
      that.parentThis.initData()
    },
    afterReject(res) {
      // 用户点击驳回后成功返回后的处理
      // console.log("驳回:"+JSON.stringify(res))
      const that = this;
      that.parentThis.initData()
      
    },
    
  }
};
</script>

<style lang='less' scoped>
/deep/ .process-engine #process-container{
  
    padding: 0;
    width: unset !important;
}
/deep/ #process-container {
  width: unset !important;
}
/deep/ #process-container .process-item .info-fullMessage {
  max-width: 1200px;
}
</style>
